﻿<%@ WebHandler Language="C#" Class="ImageHandler" %>

using System;
using System.Web;
using System.IO;

public class ImageHandler : IHttpHandler
{
    private const string UPLOAD_FOLDER = "~/uploadImage/";
    /// <summary>
    /// 上传文件夹
    /// </summary>
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            HttpPostedFile myFile = context.Request.Files["fulFile"];
            if (myFile != null)
            {
                if (myFile.InputStream.Length != 0)
                {
                    string originalFileName = Path.GetFileName(myFile.FileName);     //原文件名                        
                    string newFileName = string.Format("{0}_{1}", Guid.NewGuid(), originalFileName);   //新文件名---组成形式：  GUID + 下划线 + 原文件名
                    string fileAbsPath = context.Server.MapPath(UPLOAD_FOLDER) + newFileName;   //绝对路径
                    myFile.SaveAs(fileAbsPath);
                    context.Response.Write(newFileName);
                }
            }
        }
        catch (Exception)
        {
            context.Response.Write("0");
        }

    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}